package com.zhentao.service.impl;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.mapper.DoctorInfoMapper;
import com.zhentao.pojo.DoctorInfo;
import com.zhentao.service.DoctorInfoService;
import com.zhentao.vo.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author lenovo
* @description 针对表【doctor_info(医生信息表)】的数据库操作Service实现
* @createDate 2025-08-06 21:23:31
*/

@Service
public class DoctorInfoServiceImpl extends ServiceImpl<DoctorInfoMapper, DoctorInfo>
    implements DoctorInfoService{
    @Autowired
    private DoctorInfoMapper doctorInfoMapper;
    @Override
    public Page<DoctorInfo> findPage(Query query) {
        // 1. 初始化分页（page=当前页，size=每页条数）
        // 添加默认值以防止NullPointerException
        int page = (query.getPage() != null) ? query.getPage() : 1;
        int size = (query.getSize() != null) ? query.getSize() : 10;
        Page<DoctorInfo> pageResult = new Page<>(page, size);

        // 2. 构建查询条件
        QueryWrapper<DoctorInfo> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(query.getDoctorName())) {
            wrapper.like("doctor_name", query.getDoctorName()); // 模糊查询医生姓名
        }
        if (StringUtils.isNotBlank(query.getDepartment())) {
            wrapper.like("department", query.getDepartment()); // 模糊查询科室
        }

        // 3. 执行分页查询
        return doctorInfoMapper.selectPage(pageResult, wrapper);
    }

}
